package zhangxin;

public class GoodsDemo {
    public static void main(String[] args) {
        Phone p = new Phone("P001", "XPhone 15", 2800, 3999, "Android 14", 256);
        System.out.println("—— 商品信息 ——");
        System.out.println(p);
        p.unlock();
    }
}
class Goods {
    private String id;
    private String name;
    private double cost;
    private double price;
    public Goods() {}
    public Goods(String id, String name, double cost, double price) {
        this.id = id;
        this.name = name;
        this.cost = cost;
        this.price = price;
    }
    public double calcProfit() {
        return price - cost;
    }
//    public String getId() { return id; }
//    public void setId(String id) { this.id = id; }
//    public String getName() { return name; }
//    public void setName(String name) { this.name = name; }
//    public double getCost() { return cost; }
//    public void setCost(double cost) { this.cost = cost; }
//    public double getPrice() { return price; }
//    public void setPrice(double price) { this.price = price; }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String toString() {
        return String.format("编号：%s  名称：%s  进价：%.2f  售价：%.2f  利润：%.2f",
                id, name, cost, price, calcProfit());
    }
}
class Phone extends Goods {
    private String os;
    private int storage;
    public Phone() {}
    public Phone(String id, String name, double cost, double price,
                 String os, int storage) {
        super(id, name, cost, price);
        this.os = os;
        this.storage = storage;
    }
    public void unlock() {
        System.out.println("手机 " + getName() + " 支持面部识别 + 屏下指纹解锁！");
    }
    public String getOs() { return os; }
    public void setOs(String os) { this.os = os; }
    public int getStorage() { return storage; }
    public void setStorage(int storage) { this.storage = storage; }
    @Override
    public String toString() {
        return super.toString() + String.format("  OS：%s  存储：%dGB", os, storage);
    }
}